define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'token/index',
        add_url: 'token/add',
        edit_url: 'token/edit',
        delete_url: 'token/delete',
        export_url: 'token/export',
        modify_url: 'token/modify',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID'},
                    {field: 'is_expire', hide: true},
                    {field: 'token', title: '机器码', minWidth: 300},
                    {field: 'life', title: '有效期', search: 'range', templet: function (d){
                            if (d.is_expire){
                                return '<div class="layui-table-cell" style="color: red;">' + d.life + '</div>';
                            }
                            return '<div class="layui-table-cell" style="color: green;">' + d.life + '</div>';
                        }
                    },
                    {field: 'status', search: 'select', selectList: ["禁用","启用"], title: '状态', templet: ea.table.switch, tips: '启用|禁用'},
                    {field: 'create_time', title: '创建时间', search: 'range'},
                    {width: 250, title: '操作', templet: ea.table.tool},

                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});